$(function () {
    //抽取对象
    var order_dialog = $("#order_dialog");

    $("#orderBill_datagrid").datagrid({
        fitColumns: true,
        url:'/orderBill/query.do',
        toolbar:'#orderBill_toolbar',
        striped: true,
        rownumbers: true,
        singleSelect: true,
        ctrlSelect: true,
        pagination: true,
        pageNumber: 10,
        scrollbarSize: 0,
        fit: true,
        columns: [[
            {field: 'sn', title: '单据编码', width: 100},
            {field: 'supplier', title: '供应商', width: 100},
            {field: 'productName', title: '商品名称', width: 100},
            {field: 'price', title: '单价', width: 100},
            {field: 'totalNumber', title: '名称', width: 100},
            {field: 'totalAmount', title: '合计', width: 100},
            {field: 'reality', title: '实收', width: 100},
            {field: 'status', title: '状态', width: 100},
            {field: 'inputTime', title: '采购时间', width: 100}
        ]]
    })

    order_dialog.dialog({
        width: 700,
        height: 350,
        buttons: '#form_btns',
        closed: true,

    })

    $("#product_view").dialog({
        width: 700,
        height: 420,
        closed: true,
    })

//同一管理执行的方法
    var methodObj = {
        add: function () {
            //打开弹出框
            order_dialog.dialog('open');
            //设置弹出框的标题
            order_dialog.dialog('setTitle', '新增入库');
        },
        //打开关联第二个datagrit
        addProduct: function () {
          $("#product_view").dialog('open')
        },
        //关闭页面
        cancel: function () {
            order_dialog.dialog('close')
        },
        //高级查询
        query:function () {
          var keyword = $("#keyword").textbox('getValue');
          $("#orderBill_datagrid").datagrid('load',{
              keyword:keyword
          })
        }

    }
//同一绑定事件
    $("a[data-cmd]").click(function () {
        //获取了当前点击的方法
        var method = $(this).data("cmd");
        //调用同一执行的方法,传入执行的属性
        methodObj[method]();
    });

    //显示商品的datagrid
    $("#product_datagrid").datagrid({
        fitColumns: true,
        url: '/orderBill/list.do',
        striped: true,
        rownumbers: true,
        singleSelect: true,
        ctrlSelect: true,
        pagination: true,
        pageNumber: 10,
        scrollbarSize: 0,
        fit: true,

        columns: [[
            {field: 'sn', title: '商品编码', width: 100},
            {field: 'productName', title: '商品名称', width: 100},
            {field: 'price', title: '商品分类', width: 100},
            {field: 'costPrice', title: '零售价', width: 100}
        ]],
        //双击添加商品
        onDblClickRow:function (index,row) {
            var cl = $("#itemTr tr:first").clone();
            cl.appendTo("#tr_appendTo");
            cl.find("[tag=sn]").html(row.sn);
            cl.find("[tag=pId]").html(row.id);
            cl.find("[tag=productName]").html(row.name);
            cl.find("[tag=costPrice]").html(row.costPrice);
            $("#product_view").dialog('close');
        }
    })
})































































